<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/1/3
 * Time: 15:00
 */
//curl的5个实例
//1.抓取无访问控制文件
//header('Content-type:text/html;charset=utf-8');
//$ch = curl_init();
//curl_setopt($ch, CURLOPT_URL, "http://www.300ka.com/");
//curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果把这行注释掉的话，就会直接输出
////curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
//$result=curl_exec($ch);
//curl_close($ch);
////echo '<pre>';
////echo preg_match_all();
////preg_match_all('|<a\s+href=.+?\stitle=.+<!--.+?</a>|',$result,$res);-->
//var_dump($res);

//echo htmlspecialchars($result);
//echo '<pre>';

//获取爱奇艺网址的http://www.300ka.com/中的最新网址
header('Content-type:text/html;charset=utf-8');
$url='http://www.300ka.com/';
$lines_string=file_get_contents($url);
preg_match_all("|<h2>(<a\s+href=.+?\stitle=.+?>.+?</a>)</h2>|",$lines_string,$res);
$arr=explode('"',$res[0][0]);

//获取爱奇艺的二层网址中的账号密码
$IqiyiUrl=$arr[1];
$Iqiyi_string=file_get_contents($IqiyiUrl);
preg_match_all("|>账号.+?密码.+?<|",$Iqiyi_string,$IqiyiRes);
$count=count($IqiyiRes[0]);
$accountArr=array();
foreach ($IqiyiRes[0] as $key=>$v){
    $val0=ltrim($v,'>');
    $val1=rtrim($val0,'<');
    $accountArr[$key]=$val1;
}
var_dump($accountArr);







//2.使用代理抓取文件
//header('Content-type:text/html;charset=utf-8');
//$ch=curl_init();
//curl_setopt($ch,CURLOPT_URL,"http://www.baidu.com");
//curl_setopt($ch,CURLOPT_HEADER,false);
//curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL,true);
////curl_setopt($ch,CURLOPT_PROXY,'125.21.23.6:8080');
//$result=curl_exec($ch);
//curl_close($ch);
//echo htmlspecialchars($result);

//3.post数据后，抓取数据
//header('Content-type:text/html;charset=utf-8');
//$ch=curl_init();
//$data = array('name' => 'test', 'sex'=>1,'birth'=>'20101010');
//curl_setopt($ch,CURLOPT_URL,"http://www.baidu.com");
//curl_setopt($ch,CURLOPT_POST,1);
//curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
//$result=curl_exec($ch);

//














